/**
 * class to display missions
 */
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class MissionPanel extends JPanel{

	/**
	 * Field BABAI.
	 * (value is 800)
	 */
	private static final int BABAI = 800;

	/**
	 * Field YIQIAN.
	 * (value is 1000)
	 */
	private static final int YIQIAN = 1000;

	/**
	 * Field YIDIANLIU.
	 * (value is 1.6)
	 */
	private static final double YIDIANLIU = 1.6;
	
	/**
	 * Field YIDIANWU.
	 * (value is 1.5)
	 */
	private static final double YIDIANWU = 1.5;
	
	/**
	 * Field SHIWU.
	 * (value is 15)
	 */
	private static final int SHIWU = 15;

	/**
	 * Field YIWAN.
	 * (value is 10000)
	 */
	private static final int YIWAN = 10000;

	/**
	 * Field SHI.
	 * (value is 10)
	 */
	private static final int SHI = 10;

	/**
	 * Field BAWAN.
	 * (value is 80000)
	 */
	private static final int BAWAN = 80000;

	/**
	 * Field a2.
	 */
	/**
	 * Field a1.
	 */
	/**
	 * Field r2.
	 */
	/**
	 * Field r1.
	 */
	public static JLabel R1=null, R2=null, A1=null, A2=null;

	/**
	 * Field award2.
	 */
	/**
	 * Field award1.
	 */
	/**
	 * Field robot.
	 */
	/**
	 * Field money.
	 */
	public static int Money=0, Robot=0, Award1=0, Award2=0;
	
	/**
	 * Constructor for MissionPanel.
	 */
	public MissionPanel() {
		Money=BAWAN;
		Robot=SHI;
		Award1=YIWAN;
		Award2=YIWAN;
		setSize(BABAI, YIQIAN);
		setLayout(new GridLayout(SHIWU, 1));
		add(new JLabel("Mission 1:"));
		R1=new JLabel("Requirement: Own " + Money + " money");
		add(R1);
		A1=new JLabel("Award: " + Award1 + " money");
		add(A1);
		final JButton recieve1=new JButton("Receive Award");
		recieve1.addActionListener(new Recieve1Listener());
		add(recieve1);
		add(new JLabel("Mission 2:"));
		R2=new JLabel("Requirement: Own " + Robot + " robots");
		add(R2);
		A2=new JLabel("Award: " + Award2 + " money");
		add(A2);
		final JButton recieve2=new JButton("Receive Award");
		recieve2.addActionListener(new Recieve2Listener());
		add(recieve2);
		add(new JLabel("Mission 3:"));
		add(new JLabel("Requirement: Have been to all the planets"));
		add(new JLabel("Award: 999999 money"));
		final JButton recieve3=new JButton("Receive Award");
		recieve3.addActionListener(new Recieve3Listener());
		add(recieve3);
		add(new JLabel(""));
		final Button exitButton=new Button("Exit");
		exitButton.addActionListener(new ExitMissionListener());
		add(exitButton);
	}
	
	/**
	 * @author Master
	 */
	public static class Recieve1Listener implements ActionListener{

		/**
		 * Method toString.
		
		 * @return String */
		@Override
		public String toString() {
			return "Recieve1Listener []";
		}

		/**
		 * Method actionPerformed.
		 * @param e ActionEvent
		
		 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
		@Override
		public void actionPerformed(ActionEvent e) {
			if (PlayerInfo.Money >= Money){
				PlayerInfo.Money+=Award1;
				MarketPlaceScreen.Money.setText("" + PlayerInfo.Money);
				Money=(int) (Money * YIDIANWU);
				Award1=(int) (Award1 * YIDIANLIU);
				
				R1.setText("Requirement: Own " + Money + " money");
				A1.setText("Award: " + Award1 + " money");
			}
			else JOptionPane.showMessageDialog(
					ConfigurationScreen.MyFrame, "Mission Not Completed");
		}
		
	}
	
	/**
	 * @author Master
	 */
	public static class Recieve2Listener implements ActionListener{

		/**
		 * Field JIU.
		 * (value is 9)
		 */
		private static final int JIU = 9;

		/**
		 * Method toString.
		
		 * @return String */
		@Override
		public String toString() {
			return "Recieve2Listener []";
		}

		/**
		 * Method actionPerformed.
		 * @param e ActionEvent
		
		 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
		@Override
		public void actionPerformed(ActionEvent e) {
			if (PlayerInfo.GoodOwned[JIU] >= Robot){
				PlayerInfo.Money+=Award2;
				MarketPlaceScreen.Money.setText("" + PlayerInfo.Money);
				Robot=(int) (Robot * YIDIANWU);
				Award2=(int) (Award2 * YIDIANLIU);
				R2.setText("Requirement: Own " + Robot + " robots");
				A2.setText("Award: " + Award2 + " money");
			}
			else JOptionPane.showMessageDialog(
					ConfigurationScreen.MyFrame, "Mission Not Completed");
		}
		
	}
	
	/**
	 * @author Master
	 */
	public static class Recieve3Listener implements ActionListener{

		/**
		 * Method toString.
		
		 * @return String */
		@Override
		public String toString() {
			return "Recieve3Listener []";
		}

		/**
		 * Method actionPerformed.
		 * @param e ActionEvent
		
		 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
		@Override
		public void actionPerformed(ActionEvent e) {
			JOptionPane.showMessageDialog(
					ConfigurationScreen.MyFrame, "Mission Not Completed");
		}
		
	}
}
